package pres.lnk.learn.designpattern.h_filter.criteria;

import pres.lnk.learn.designpattern.h_filter.Person;

/**
 * @Author lnk
 * @Date 2018/2/8
 */
public class AndCriteria extends AbstractCriteria<Person>  {
    /**
     * 数组可改成集合，然后增加add方法动态添加条件
     */
    private Criteria<Person>[] criterion;

    public AndCriteria(Criteria<Person>... criterion){
        if(criterion == null && criterion.length == 0){
            throw new IllegalArgumentException("条件不能这空");
        }
        this.criterion = criterion;
    }

    @Override
    public boolean meet(Person person) {
        for (Criteria<Person> c : criterion) {
            if(!c.meet(person)){
                return false;
            }
        }
        return true;
    }
}
